<template>
  <div>
    <h1 style="color:red;">Count组件求和为{{$store.state.sum}}</h1>
    <input type="text" v-model="name_value">
    <button @click="addPerson">添加</button>
    <ul>
      <li v-for="person in personList" :key="person.id">{{person.name}}</li>
    </ul>
  </div>
</template>

<script>
export default {
  name:'Person',
  data(){
    return {
      name_value:'',
      personList:this.$store.state.personList
    }
  },
  methods:{
    addPerson(){
      this.$store.commit('ADD_PERSON',{id:Math.random(),name:this.name_value})
      this.name_value=''
    }
  }
}
</script>

<style>

</style>